package Chat.Run;

import Chat.Donnees.*;

/**
 * Pour Tester les Classes dans Chat.Donnes
 *
 * @author Ndanja & Papa Abdou
 */
public class TestEntity {

    public static void main(String args[]) {
        try {
            // creates a contact
            Contact yo = new Contact("lolo", "192.168.1.1");
            // creates a Hello message and converts to a byte array
            Hello hola = new Hello(yo, false);
            byte[] b1 = Message.toByteArray(hola);
            // creates a Chat message and converts to a byte array
            Chat chacha = new Chat(yo, "chachacha");
            byte[] b2 = Message.toByteArray(chacha);
            // retrieves the Hello Message
            Message m = Message.getMessage(b1, 0, b1.length);
            if (m instanceof Hello) {
                Hello h = (Hello) m;
                System.out.println(h);
            }
            // retrieves the Chat Message
            m = Message.getMessage(b2, 0, b2.length);
            if (m instanceof Chat) {
                Chat c = (Chat) m;
                System.out.println(c);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
